/*
 * @Description:
 * @Author: 稽辉
 * @Date: 2025-02-10 10:18:26
 * @LastEditTime: 2025-03-19 10:23:21
 * @LastEditors: 稽辉
 */
import type {
  OrderCreateParams,
  OrderListParams,
  OrderListResult,
  OrderLogisticResult,
  OrderPreResult,
  OrderResult,
} from '@/types/order'
import { http } from '@/utils/http'

//获取预付订单
export const getMemberOrderPreAPI = () => {
  return http<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre',
  })
}
//立即购买的订单
export const getMemberOrderNowAPI = (data: { skuId: string; count: string; address?: string }) => {
  return http<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre/now',
    data,
  })
}
//提交订单
export const postMemberOrderAPI = (userId: number) => {
  return http<number>({
    method: 'POST',
    url: `/order/post-order/${userId}`,
  })
}

//直接购买
export const postOrderDirect = (data: {}) => {
  return http<number>({
    method: 'POST',
    url: `/order/order-direct-purchase`,
    data,
  })
}
//再次购买
export const PayOrderAgainAPI = (orderId: number) => {
  return http<number>({
    method: 'GET',
    url: `/order/pay-order-again?orderId=${orderId}`,
  })
}

//获取订单详情
export const getMemberOrderByIdAPI = (id: number, userId: number) => {
  return http<OrderResult>({
    method: 'GET',
    url: `/order/get-order-by-id?orderId=${id}&userId=${userId}`,
  })
}
/** * 模拟发货-内测版 *
 * @description 在DEV环境下使用，仅在订单状态为待发货时，
 * 可模拟发货，调用后订单状态修改为待收货，包含模拟物流。
 * @param id 订单id */
export const getMemberOrderConsignmentByIdAPI = (id: string) => {
  return http({ method: 'GET', url: `/member/order/consignment/${id}` })
}

/**
 * 确认收货
 * @description 仅在订单状态为待收货时，可确认收货。
 * @param id 订单id
 */
export const putMemberOrderReceiptByIdAPI = (id: string) => {
  return http<OrderResult>({
    method: 'PUT',
    url: `/member/order/${id}/receipt`,
  })
}

/**
 * 获取订单物流
 * @description 仅在订单状态为待收货，待评价，已完成时，可获取物流信息。
 * @param id 订单id
 */
export const getMemberOrderLogisticsByIdAPI = (id: string) => {
  return http<OrderLogisticResult>({
    method: 'GET',
    url: `/member/order/${id}/logistics`,
  })
}
/**
 * 删除订单
 * @description 仅在订单状态为待评价，已完成，已取消时，可删除订单。
 * @param data ids 订单集合 */
export const deleteMemberOrderAPI = (orderId: number) => {
  return http({ method: 'DELETE', url: `/order/delete-order-by-id/${orderId}` })
}

/**
 * 获取订单列表
 * @param data orderState 订单状态
 */
export const getMemberOrderAPI = (data: OrderListParams) => {
  return http<OrderListResult>({
    method: 'POST',
    url: `/order/get-order-by-state`,
    data,
  })
}
